<?php
header("content-type:text/html;charset=utf-8");
//导入文件
require ('./models/Model.class.php');
//配置文件
require('./configs/config.php');


//得到对象
// $model = new Model('yonghu');
// var_dump($model);

//导入控制类
// require('./controllers/IndexController.class.php');
// require('./controllers/GoodsController.class.php');
// require('./controllers/UsersController.class.php');

//实现自动加载类
function mvc_autoload($classname){
    echo $classname;
    //判断类和方法是否存在 不存在则引入
    if(file_exists("./models/{$classname}.class.php")){
        //存在则引入
        require("./models/{$classname}.class.php");
    }elseif(file_exists("./controllers/{$classname}.class.php")){
        require "./controllers/{$classname}.class.php";
    }else{
        header('HTTP/1.0 404 not found'); //非ie
        header('Status:404 not found');  //兼容ie
        echo "<h1>404</h1>";
        exit;
    }
}

//引入smarty
require ('./libs/Smarty.class.php');

//此时smarty的自动加载函数与自己定义的smarty函数冲突 采用spl_autoload_register()解决
spl_autoload_register('mvc_autoload');
$smarty = new Smarty();
// var_dump($smarty);
//模板文件
$smarty->template_dir = "./views";
//编译文件目录
$smarty->compile_dir="./runtime/views_c";
//配置文件保存目录
$smarty->config_dir="./configs";
//缓存文件
$smarty->cache_dir = "./runtime/caches";

//定界符
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
//缓存配置
$smarty->caching=false;
$smarty->cache_lifetime=10;




//接受canshu 
$c = empty($_GET['c'])?'Index':$_GET['c'];
$a = empty($_GET['a'])?'index':$_GET['a'];

$classname = $c.'Controller';
//实例化控制器
$controller = new $classname();
// var_dump($controller);
$controller->$a();
echo "<hr>";

// //跳转     
// echo   "<a  href ='index.php?c=Users&a=index'>跳转用户页</a>";
// echo "<br>";
// echo   "<a  href ='index.php'>跳转首页</a>";


?>